package org.feng.service.impl;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;

/**
 * TODO 类的描述
 *
 * @version V1.0
 * @author: fengjinsong
 * @date: 2022年07月15日 14时09分
 */
@Slf4j
public class ManyStreamService {

    public static void main(String[] args) {
        ManyStreamService manyStreamService = new ManyStreamService();

        Mono<String> stringMono = Mono.empty();

        final int anInt = ThreadLocalRandom.current().nextInt(0, 10);
        if (anInt > 3) {
            stringMono = manyStreamService.initMono();
        }

        log.info("anInt ->> {}", anInt);
        stringMono.doOnNext(e -> log.info("on next --> {}", e))
                .thenMany(manyStreamService.initFlux())
                .doOnNext(s -> log.info("flux=-----> {}", s))
                .subscribe();
    }


    private Flux<String> initFlux() {
        return Flux.fromStream(IntStream.rangeClosed(1, 10).mapToObj(String::valueOf));
    }

    private Mono<String> initMono() {
        return Mono.just("1");
    }
}
